<?php

/**
 * This is the model class for table "CzasPracy".
 *
 * The followings are the available columns in table 'CzasPracy':
 * @property integer $idCzasPracy
 * @property string $Data
 * @property string $Godzina_poczatek
 * @property string $Godzina_koniec
 * @property string $Flaga
 * @property integer $idLekarz
 */
class CzasPracy extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return CzasPracy the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'CzasPracy';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('Data, Godzina_poczatek, Godzina_koniec, Flaga, idLekarz, Dzien_tygodnia', 'required'),
			array('idLekarz', 'numerical', 'integerOnly'=>true),
			array('Flaga', 'length', 'max'=>3),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('idCzasPracy, Data, Dzien_tygodnia, Godzina_poczatek, Godzina_koniec, Flaga, idLekarz', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
                    	'lekarz' => array(self::BELONGS_TO, 'Lekarz', 'idLekarz'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'idCzasPracy' => 'Id Czas Pracy',
			'Data' => 'Obowiązuje od',
                        'Dzien_tygodnia' => 'Dzień tygodnia',
			'Godzina_poczatek' => 'Od',
			'Godzina_koniec' => 'Do',
			'Flaga' => 'Tryb',
			'idLekarz' => 'Id Lekarz',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('idCzasPracy',$this->idCzasPracy);
		$criteria->compare('Data',$this->Data,true);
		$criteria->compare('Dzien_tygodnia',$this->Dzien_tygodnia,true);
                $criteria->compare('Godzina_poczatek',$this->Godzina_poczatek,true);
		$criteria->compare('Godzina_koniec',$this->Godzina_koniec,true);
		$criteria->compare('Flaga',$this->Flaga,true);
		$criteria->compare('idLekarz',$this->idLekarz);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
                        'sort'=>array('defaultOrder'=>'Data DESC'),
		));
	}
}